package data;

import java.util.GregorianCalendar;

import miscellaneous.TimeSupport;

/**
 * This is a message that will be sent from an appointment
 * to a user. Each user gets a different message.
 * @author daniel
 */
public class Message extends Data {

	
	private Meeting meeting;
	private User receiver;
	private String subject;
	private String description;
	private GregorianCalendar sendTime;
	private GregorianCalendar readTime;
	
	
	/**
	 * Constructor
	 */
	public Message(Meeting meeting) {
		super();
		this.meeting = meeting;
		
	}
	
	public Message(Meeting meeting, User receiver, String subject, String description, GregorianCalendar sendTime, GregorianCalendar readTime) {
		this(meeting);
		this.receiver = receiver;
		this.subject = subject;
		this.description = description;
		this.sendTime = sendTime;
		this.readTime = readTime;
	}
	
	public Meeting getMeeting() {
		return meeting;
	}
	
	public void setMeeting(Meeting meeting) {
		this.meeting = meeting;
	}
	
	public User getReceiver() {
		return receiver;
	}

	public void setReceiver(User receiver) {
		this.receiver = receiver;
		changeSupport.firePropertyChange("update", null, null);
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
		changeSupport.firePropertyChange("update", null, null);

	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public GregorianCalendar getSendTime() {
		return sendTime;
	}

	public void setSendTime(GregorianCalendar sendTime) {
		this.sendTime = sendTime;
		changeSupport.firePropertyChange("update", null, null);

	}

	public GregorianCalendar getReadTime() {
		return readTime;
	}

	public void setReadTime(GregorianCalendar readTime) {
		this.readTime = readTime;
		changeSupport.firePropertyChange("update", null, null);

	}

	@Override
	public int compareTo(Data o) {
		if(o instanceof Message)
			return (int) (((Message)o).sendTime.getTimeInMillis() - this.sendTime.getTimeInMillis());
		System.err.println("Comparing message to some other class");
		return 0;
	}
	
	@Override
	public String toString() {
		String format = "[Sendt: " + TimeSupport.showTimeNice(sendTime) + " " + 
		TimeSupport.showDateNice(sendTime) +"]";
		format += " | Emne:"+subject;
		format += " | "+description;
		format += " | (møteleder: " + ((meeting == null) ? "møte er null" :meeting.getOwner()) + ")";
		return format;
	}

}